﻿
@if (ShowHeader)
{
    <div class="navbar bg-neutral rounded">
        <a class="btn btn-ghost" href="/">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" /></svg>
        </a>
        <div class="flex pl-2 text-lg font-bold">
            <div class="text-gray-400 mr-2">Result</div>
            <div>@ExecutionSummary?.ExecutionId</div>
        </div>
    </div>
}

<div class="card px-2 pt-1 pb-2">
    <div class="card-body p-1">
        @if (ExecutionSummary != null)
        {
            <div class="shadow stats rounded">
                <div class="stat bg-base-200 py-3">
                    <div class="stat-title text-sm">Workload</div>
                    <div class="stat-value text-base">
                        @ExecutionSummary.Workload
                    </div>
                </div>
                <div class="stat bg-base-200 py-3">
                    <div class="stat-title text-sm">WorkerCount</div>
                    <div class="stat-value text-base">
                        @ExecutionSummary.WorkerCount
                    </div>
                </div>
                <div class="stat bg-base-200 py-3">
                    <div class="stat-title text-sm">Concurrency</div>
                    <div class="stat-value text-base">
                        @ExecutionSummary.Concurrency
                    </div>
                </div>
                <div class="stat bg-base-200 py-3">
                    <div class="stat-title text-sm">TotalRequest</div>
                    <div class="stat-value text-base">
                        @(ExecutionSummary.TotalRequest == long.MaxValue ? "-" : ExecutionSummary.TotalRequest.ToString())
                    </div>
                </div>
                <div class="stat bg-base-200 py-3">
                    <div class="stat-title text-sm">Parameters</div>
                    <div class="stat-value text-base">
                        @if (ExecutionSummary.Parameters.Count != 0)
                        {
                            <label class="btn btn-outline rounded btn-xs" @onclick=ShowParameters>
                                show
                            </label>
                        }
                    </div>
                </div>
            </div>
        }
    </div>
</div>

<table class="table w-full rounded shadow">
    <thead>
        <tr>
            <th class="text-center normal-case w-[50px]">STATUS</th>
            <th class="text-center normal-case">#Succeed</th>
            <th class="text-center normal-case">#Error</th>
            <th class="text-center normal-case">Max(ms)</th>
            <th class="text-center normal-case">Min(ms)</th>
            <th class="text-center normal-case">Avg(ms)</th>
            <th class="text-center normal-case">Median(ms)</th>
            <th class="text-center normal-case">90%ile(ms)</th>
            <th class="text-center normal-case">95%ile(ms)</th>
            <th class="text-center normal-case">RPS</th>
            <th class="text-center normal-case"></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in ExecutionResults)
        {
            <tr class="hover">
                <td class="text-center">
                    <div>
                        @switch (item.ExecutionStatus)
                        {
                            case ExecutionStatus.Running:
                                <svg xmlns="http://www.w3.org/2000/svg" class="inline animate-spin  h-5 w-5 text-white" fill="none" viewBox="0 0 24 24">
                                    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                                    <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                                </svg>
                                break;
                            case ExecutionStatus.Failed:
                                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current text-red-500 scale-125">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="4" d="M6 18L18 6M6 6l12 12"></path>
                                </svg>
                                break;
                            case ExecutionStatus.Succeed:
                                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-4 h-4 stroke-current text-green-500 scale-125">
                                    <path stroke="none" d="M0 0h24v24H0z" />
                                    <path stroke-width="4" d="M5 12l5 5l10 -10" />
                                </svg>
                                break;
                        }
                    </div>
                </td>
                <td class="text-center">@item.SucceedCount</td>
                <td class="text-center">
                    @if (item.ErrorCount >= 1)
                    {
                        <label class="text-red-500">@item.ErrorCount</label>
                    }
                    else
                    {
                        @item.ErrorCount
                    }
                </td>
                <td class="text-center">@item.Max.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Min.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Avg.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Median?.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Percentile90?.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Percentile95?.TotalMilliseconds.ToString("0.00")</td>
                <td class="text-center">@item.Rps.ToString("0.00")</td>
                <td class="text-center">
                    <button class="btn btn-square btn-ghost btn-xs rounded" @onclick=@(() => ShowWorkerInfo(item.WorkerId))>
                      <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-6 h-5 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"></path></svg>
                    </button>
                </td>
            </tr>
        }
    </tbody>
</table>